
package system.base;

import framework.core.*;
import system.data.*;
/*
	Author    :chengbiao.he
	CreateTime:2008-02-22 14:03:46
*/
public class WarehouseStaffSrv extends IHandler
{

	public WarehouseStaffSrv() 
	{
		super();
	}
	private void deleteWarehouseStaff(DBConnection con,SrvContext context) throws Exception
	{
		String[] ids = context.getParameterValues("ids");
		WarehouseStaff obj = null;
		for(int i=0;i<ids.length;i++)
		{
			obj = WarehouseStaff.fetch(con,ids[i]);
			if(obj!=null) obj.delete(con);
		}
	}
	private void saveWarehouseStaff(DBConnection con,SrvContext context,ILoginContext loginContext) throws Exception
	{
		String id = context.getString("Id",null);
		WarehouseStaff obj;
		if((id==null)||(id.equals("")))   //add
		{
			obj = WarehouseStaff.fetch();
    	}
    	else                     //update
    	{
    		obj = WarehouseStaff.fetch(con,id);
    	}
		WarehouseStaffPageData data = (WarehouseStaffPageData)PageData.fromForm(context,WarehouseStaffPageData.class);
		context.setValue("WarehouseStaffPageData",data);
		obj.fill(data);
		obj.save(con);
	}
	private void listWarehouseStaff(DBConnection con,SrvContext context,String path) throws Exception
	{
		WarehouseStaffSearchEvent event = (WarehouseStaffSearchEvent)SearchEvent.fromForm(context,WarehouseStaffSearchEvent.class);
		context.setSessionValue("WarehouseStaffSearchEvent",event);
		context.setNextUrl(path+"WarehouseStaffList.jsp");
	}
	private void backWarehouseStaff(DBConnection con,SrvContext context,String path) throws Exception
	{
		context.setNextUrl(path+"WarehouseStaffList.jsp");
	}
	
	public void doAction(DBConnection con,SrvContext context,ILoginContext loginContext) throws Exception
	{
		String action_code = context.getActionCode();
		String path = "/system/base/";
		
		if(action_code.equalsIgnoreCase("listWarehouseStaff"))
		{
			listWarehouseStaff(con,context,path);
			return;
		}
		if(action_code.equalsIgnoreCase("viewWarehouseStaff"))
		{
			String id = context.getString("Id",null);
			WarehouseStaff obj = WarehouseStaff.fetch(con,id);
			context.setValue("WarehouseStaff",obj);
			context.setNextUrl(path+"WarehouseStaffView.jsp");
			return;
		}
		if(action_code.equalsIgnoreCase("deleteWarehouseStaff"))
		{
			context.setErrorUrl(path+"WarehouseStaffList.jsp");
			deleteWarehouseStaff(con,context);
			backWarehouseStaff(con,context,path);
			return;
		}
			
		if(action_code.equalsIgnoreCase("toAddWarehouseStaff"))
		{
			WarehouseStaff obj = WarehouseStaff.fetch();
			WarehouseStaffPageData data = (WarehouseStaffPageData)PageData.fromTable(obj,WarehouseStaffPageData.class);
			context.setValue("WarehouseStaffPageData",data);
			context.setNextUrl(path+"WarehouseStaffEdit.jsp");
			return;
		}
		if(action_code.equalsIgnoreCase("toUpdateWarehouseStaff"))
		{
			String id = context.getString("Id",null);
			WarehouseStaff obj = WarehouseStaff.fetch(con,id);
			WarehouseStaffPageData data = (WarehouseStaffPageData)PageData.fromTable(obj,WarehouseStaffPageData.class);
			context.setValue("WarehouseStaffPageData",data);
			context.setNextUrl(path+"WarehouseStaffEdit.jsp");
			return;
		}
		if(action_code.equalsIgnoreCase("toCopyWarehouseStaff"))
		{
			String id = context.getString("Id",null);
			WarehouseStaff obj = WarehouseStaff.copy(WarehouseStaff.fetch(con,id));
			WarehouseStaffPageData data = (WarehouseStaffPageData)PageData.fromTable(obj,WarehouseStaffPageData.class);
			context.setValue("WarehouseStaffPageData",data);
			context.setNextUrl(path+"WarehouseStaffEdit.jsp");
			return;
		}
		if(action_code.equalsIgnoreCase("saveWarehouseStaff"))
		{
			context.setErrorUrl(path+"WarehouseStaffEdit.jsp");
			saveWarehouseStaff(con,context,loginContext);
			backWarehouseStaff(con,context,path);
			return;
		}
		if(action_code.equalsIgnoreCase("saveAndNewWarehouseStaff"))
		{
			context.setErrorUrl(path+"WarehouseStaffEdit.jsp");
			saveWarehouseStaff(con,context,loginContext);
			WarehouseStaff obj = WarehouseStaff.fetch();
			WarehouseStaffPageData data = (WarehouseStaffPageData)PageData.fromTable(obj,WarehouseStaffPageData.class);
			context.setValue("WarehouseStaffPageData",data);
			context.setNextUrl(path+"WarehouseStaffEdit.jsp");			
			return;
		}
		if(action_code.equalsIgnoreCase("backListWarehouseStaff"))
		{
			backWarehouseStaff(con,context,path);
			return;
		}
		
		//add by chengbiao.he start

		//add by chengbiao.he end

		Logger.throwException("WarehouseStaffSrv","unknown action_code="+action_code);
	}
}
